#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QGridLayout>
#include <QKeyEvent>
#include "label.h"
#include "pushbutton.h"

#define LabelX  20
#define LabelY  10
#define GW1 480
#define GH1 450
#define GW2 960
#define GH2 540
#define GW3 1280
#define GH3 720
#define GW4 1680
#define GH4 820
#define GEAR 3
#define PI acos(-1.0)

class GameLayout;
class Graph;
class GLabel;
class Border;
class Operate;

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    GameLayout* gl;
    Graph* gp;
    Operate* op;
    int time_id;

private:
    Ui::Widget *ui;

public:
    explicit Widget(QWidget *parent = 0);
    void SetMenuSize(uint gear);
    void isgameover(int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    void bestscoreup(void);
    ~Widget();

private:
    void keyPressEvent(QKeyEvent* event);
    void timerEvent(QTimerEvent* event);

public slots:
    void btn_new_game(void);
    void btn_close_game(void);
};

//游戏界面布局
class GameLayout
{
private:
    QGridLayout* GL;
    QGridLayout* gl1;
    QGridLayout* gl2;
    TLabel* title[2];

public:
    SLabel* score[2];
    int* arr[LabelX][LabelY];
    GLabel* lab[LabelX][LabelY];
    PushButton* pb[2];

public:
    GameLayout(QWidget* parent=0);
    void GameLayoutrebuild(void);
    ~GameLayout();
};

//图形边界
class Border
{
public:
    int uBorder;
    int dBorder;
    int lBorder;
    int rBorder;
public:
    Border();
    reBorder(int ub,int db,int lb,int rb);
    ~Border();
};

//图形生成
class Graph
{
public:
    int PosX;
    int PosY;
    bool IsMove;
    char* color;
    int* arr[LabelX][LabelY];
    GLabel* lab[LabelX][LabelY];
    Border* border;

public:
   Graph(int* arr[LabelX ][LabelY],GLabel* lab[LabelX][LabelY]);
   void GraphBulid(int* x,int* y);
   void SGraph(int* x,int* y);
   void ZGraph(int* x,int* y);
   void JGraph(int* x,int* y);
   void LGraph(int* x,int* y);
   void TGraph(int* x,int* y);
   void IGraph(int* x,int* y);
   void OGraph(int* x,int* y);
   ~Graph();
};

//操坐
class Operate
{
public:
    Graph* graph;

public:
    Operate(Graph* graph);
    void uGraph(Border* border,int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    void dGraph(Border* border,int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    void lGraph(Border* border,int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    void rGraph(Border* border,int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    void remove(SLabel* score,int* arr[LabelX][LabelY],GLabel* lab[LabelX][LabelY]);
    ~Operate();
};

#endif // WIDGET_H
